<?php
	$title_for_layout = $this->Html->clean($post['Post']['title']);
	$this->set(compact('title_for_layout'));
	$_blog_slug = (isset($post['Blog'])) ? $post['Blog'][Configure::read('LilBlogs.blogSlugField')] : null;
?>
<div id="post-view">
<div class="post">
	<h1><?php echo $title_for_layout; ?></h1>
	<div class="meta">
		<?php
			if (!empty($post['Author'][Configure::read('Lil.authorDisplayField')])) {
				printf(__d('lil_blogs', 'Posted %1$s by %2$s', true),
					$this->Time->timeAgoInWords($post['Post']['created']),
					$post['Author'][Configure::read('Lil.authorDisplayField')]
				);
			} else {
				printf(__d('lil_blogs', 'Posted %s', true),
					$this->Time->timeAgoInWords($post['Post']['created'])
				);
			}
			
			// display list of categories
			if (!empty($post['Category'])) {
				echo ' ' . __d('lil_blogs', 'in', true) . ' ';
				
				echo $this->Text->toList(
					Set::format(
						$post, 
						$this->Html->link('%1$s', array(
							'controller' => 'posts',
							'action'     => 'index',
							'blog'       => $_blog_slug,
							'category'   => '%2$s'
						)), 
						array('Category.{n}.name', 'Category.{n}.id')
					),
					__d('lil_blogs', 'and', true)
				);
			}
			
			// show no of comments
			if (Configure::read('LilBlogs.commentAssociation')) {
				echo ' (';
				// this is neccessary because of i18n extraction
				$comment_count = $post['Post']['no_comments'];
				echo $this->Html->link(sprintf(
					__dn('lil_blogs', '1 comment', '%d comments', $comment_count, true), $comment_count),
					array(
						'plugin'     => 'lil_blogs',
						'controller' => 'posts',
						'action'     => 'view',
						'blog'       => $blog['Blog'][Configure::read('LilBlogs.blogSlugField')],
						'post'       => $post['Post']['slug'] . '#comments',
					));
				echo ')';
			}
			
			// show "edit this post" link
			if (isset($this->Lil) && $this->Lil->user('id')) {
				echo ' | '.$this->Html->link(__d('lil_blogs', 'Edit this post', true), array(
					'admin'   => true,
					'action'  => 'edit',
					'blog_id' => $post['Post']['blog_id'],
					$post['Post']['id']
				));
			}
		?>
	</div>
	<div class="body">
	<?php
		echo $this->LilBlogs->autop($post['Post']['body']);
	?>
	</div>
</div>

<?php
	if (Configure::read('LilBlogs.commentAssociation')) {
?>
	<div class="commentlist" id="CommentList">
		<h1><?php __d('lil_blogs', 'Comments'); ?></h1><a name="comments"></a>
	<?php 
		if (empty($post['Comment'])) {
			if ($post['Post']['allow_comments']) {
	?>
		<div id="NoComments"><?php __d('lil_blogs', 'No comments yet. Please do add yours.'); ?></div>
	<?php
			}
		} else {
		$i = 1;
		foreach($post['Comment'] as $comment) {
	?>
		<div class="comment" id="c<?php echo $comment['id']; ?>">
			<div class="meta">
				<span class="commentnumber"><a href="#c<?php echo $comment['id']; ?>"><?php echo $i++; ?></a></span>
				<span class="poster"><?php echo (strlen($comment['url'])>0) ? $this->Html->link($comment['author'], $comment['url']) : $comment['author']; ?></span>
				<?php __d('lil_blogs', 'said'); ?> <?php echo $this->Time->timeAgoInWords($comment['created']); ?>:
			</div>
			<div class="message">
				<?php echo $this->Lil->autop($comment['body']); ?>
			</div>
		</div>
	<?php }} ?>
	</div>
	
	<?php if ($post['Post']['allow_comments']) { ?>
		<div class="form" id="CommentForm">
			<a name="addcomment"></a>
			<h1 id="PostComment"><?php __d('lil_blogs', 'Leave a Comment'); ?></h1>
			<?php
				echo $this->Form->create('Comment', array('url'=>Router::url(null, true).'#addcomment'));
				echo $this->Form->hidden('post_id', array('value'=>$post['Post']['id']));
				echo $this->Form->input('author', array('label'=>__d('lil_blogs', 'Author', true).':', 'error'=> __d('lil_blogs', 'Author is required.', true)));
				echo $this->Form->input('email', array('label'=>__d('lil_blogs', 'Email', true).':', 'error'=> __d('lil_blogs', 'Email in proper form is required.', true)));
				echo $this->Form->input('url', array('label'=>__d('lil_blogs', 'Url', true).':'));
				echo $this->Form->input('body', array('label'=>__d('lil_blogs', 'Body', true).':', 'error'=> __d('lil_blogs', 'Body is required.', true)));
				echo $this->Form->submit(__d('lil_blogs', 'Add my comment', true));
				echo $this->Form->end();
			?>
			<div id="FormNote"><?php __d('lil_blogs', 'Please be respectful; your comment my be edited or marked as spam, if necessary.'); ?></div>
		</div>
	<?php } else { ?>
		<div id="CommentsClosed"><?php __d('lil_blogs', 'Sorry, comments are closed for this post. If you have any further questions or comments, feel free to contact us.');?></div>
	<?php } ?>
<?php
	}
?>
</div>